#ifndef LOG_HPP_
#define LOG_HPP_

#include "Common.hpp"
#include <fstream>

class Logger{
private:
    std::string filename;                // log的输出文件名
    pthread_t pthread_id;
    std::ofstream file_out;              // 文件输出流
    std::list<std::string> MessageQueue;      // 消息队列

    pthread_mutex_t lock;
    pthread_cond_t HaveMessgae;

    // 线程回调函数
    static void* threadfunction(void *arg);

public:
    Logger() {}
    Logger(const std::string& _filename) : filename(_filename) {
        file_out.open(_filename); // ios:app 追加
    }
    void AddMessage(const std::string &msg);
    void LoggerInit();
    void WriteLog();
    void StopLogger();
};

#define LOG(str) logger.AddMessage(str)  

#endif